package com.fh.shop.api.config;

import com.fh.shop.api.interceptor.IdempotenceInterceptor;
import com.fh.shop.api.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 配置类【通过类（java代码）的方式实现配置起到和xml一样的效果】
 * <beans></beans>
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     *  <mvc:interceptors> </mvc:interceptors>
     * @param registry
     */
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor())
                .addPathPatterns("/**");
        registry.addInterceptor(idempotenceInterceptor())
                .addPathPatterns("/**");
    }
    /**
     *  <bean class="com.fh.shop.admin.interceptor.LoginInterceptor"/>
     */
    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    @Bean
    public IdempotenceInterceptor idempotenceInterceptor() {
        return new IdempotenceInterceptor();
    }
}
